
package edu.tongji.engine.def;

import java.util.HashSet;
import java.util.Set;

import edu.tongji.engine.exe.Token;

/**
 * @author David Fei
 */ 
/**
 * This is core class. All node type of this workflow engine is inherited from this interface.
 * 
 */
public abstract class Node implements java.io.Serializable{

	private Long id;
	
	private String name;
	
	private String type_name;
	
    private String description;
	
	private boolean async;
	
	private ProcessDefinition pd;
	
	private Set<Transition> arrivingTransitions = new HashSet(0);
	
	private Set<Transition> leavingTransitions = new HashSet(0);
	
	private String enterEventHandler;
	
	private String leaveEventHandler;
	
	//private String type;
	
	abstract public void EnterEnvent(Token token);
	
	abstract public void LeaveEvent(Token token);

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isAsync() {
		return async;
	}

	public void setAsync(boolean async) {
		this.async = async;
	}

	public ProcessDefinition getPd() {
		return pd;
	}

	public void setPd(ProcessDefinition pd) {
		this.pd = pd;
	}


	public String getEnterEventHandler() {
		return enterEventHandler;
	}

	public void setEnterEventHandler(String enterEventHandler) {
		this.enterEventHandler = enterEventHandler;
	}

	public String getLeaveEventHandler() {
		return leaveEventHandler;
	}

	public void setLeaveEventHandler(String leaveEventHandler) {
		this.leaveEventHandler = leaveEventHandler;
	}

	public Set<Transition> getArrivingTransitions() {
		return arrivingTransitions;
	}

	public void setArrivingTransitions(Set<Transition> arrivingTransitions) {
		this.arrivingTransitions = arrivingTransitions;
	}
	public Transition getArrivingTransition(){
		return this.getArrivingTransitions().iterator().next();
	}
	
	public void setArrivingTransition( Transition trans ){
		//this.getLeavingTransitions().clear();
		if (trans == null) {
			return;
		}
		this.arrivingTransitions.add(trans);
		trans.setTo_node(this);
		trans.setPd(this.pd);
	}

	public Set<Transition> getLeavingTransitions() {
		return leavingTransitions;
	}

	public void setLeavingTransitions(Set<Transition> leavingTransitions) {
		this.leavingTransitions = leavingTransitions;
	}
	
	public Transition getLeavingTransition(){
		return this.getLeavingTransitions().iterator().next();
	}
	
	public void setleavingTransition( Transition trans ){
		//this.getLeavingTransitions().clear();
		if (trans == null) {
			return;
		}
		this.leavingTransitions.add(trans);
		trans.setFrom_node(this);
		trans.setPd(this.pd);																				
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getType_name() {
		return type_name;
	}

	public void setType_name(String type_name) {
		this.type_name = type_name;
	}

	public void addArrivingTransition(Transition trans){
		this.arrivingTransitions.add(trans);
		trans.setTo_node(this);
		trans.setPd(this.pd);
	}
	
	public void addLeavingTransition(Transition trans){
		this.leavingTransitions.add(trans);
		trans.setFrom_node(this);
		trans.setPd(this.pd);
	}
//	public String getType() {
//		return type;
//	}
//
//	public void setType(String type) {
//		this.type = type;
//	}
}
